load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag")
load("//rust/private:unpretty.bzl", "rust_unpretty_flag")
load(":incompatible.bzl", "incompatible_flag")

package(default_visibility = ["//visibility:public"])

bzl_library(
    name = "bzl_lib",
    srcs = glob(["**/*.bzl"]),
)

rust_unpretty_flag(
    name = "unpretty",
    build_setting_default = [
        "ast-tree,expanded",
        "ast-tree",
        "expanded,hygiene",
        "expanded,identified",
        "expanded",
        "hir-tree",
        "hir,identified",
        "hir,typed",
        "hir",
        "identified",
        "mir-cfg",
        "mir",
        "normal",
    ],
)

# A flag controlling whether to rename first-party crates such that their names
# encode the Bazel package and target name, instead of just the target name.
#
# First-party vs. third-party crates are identified using the value of
# //settings:third_party_dir.
bool_flag(
    name = "rename_first_party_crates",
    build_setting_default = False,
)

# A flag specifying the location of vendored third-party rust crates within this
# repository that must not be renamed when `rename_first_party_crates` is enabled.
#
# Must be specified as a Bazel package, e.g. "//some/location/in/repo".
string_flag(
    name = "third_party_dir",
    build_setting_default = "//third_party/rust",
)

# A flag to control whether rust_library and rust_binary targets should
# implicitly depend on the *real* import macro, or on a no-op target.
bool_flag(
    name = "use_real_import_macro",
    build_setting_default = False,
)

# When set, this flag causes rustc to emit .rmeta files and use them for rlib -> rlib dependencies.
# While this involves one extra (short) rustc invocation to build the rmeta file,
# it allows library dependencies to be unlocked much sooner, increasing parallelism during compilation.
bool_flag(
    name = "pipelined_compilation",
    build_setting_default = False,
)

# A flag to control whether to link rust_binary and rust_test targets using
# cc_common.link instead of rustc.
bool_flag(
    name = "experimental_use_cc_common_link",
    build_setting_default = False,
)

# A flag to indicate that a global allocator is in use when using --@rules_rust//rust/settings:experimental_use_cc_common_link
# Users need to specify this flag because rustc generates different set of symbols at link time when a global allocator is in use.
# When the linking is not done by rustc, the `rust_toolchain` itself provides the appropriate set of symbols.
bool_flag(
    name = "experimental_use_global_allocator",
    build_setting_default = False,
)

# A flag to have coverage tooling added as `coverage_common.instrumented_files_info.metadata_files` instead of
# reporting tools like `llvm-cov` and `llvm-profdata` as runfiles to each test.
bool_flag(
    name = "experimental_use_coverage_metadata_files",
    build_setting_default = False,
)

# A flag to set rustc --sysroot flag to the sysroot generated by rust_toolchain
incompatible_flag(
    name = "experimental_toolchain_generated_sysroot",
    build_setting_default = True,
    issue = "https://github.com/bazelbuild/rules_rust/issues/2039",
)

# A flag to control whether to link libstd dynamically.
bool_flag(
    name = "experimental_link_std_dylib",
    build_setting_default = False,
)

# A flag to control whether the shell path from a shell toolchain (`@bazel_tools//tools/sh:toolchain_type`)
# is embedded into the bootstrap process wrapper for the `.sh` file.
bool_flag(
    name = "experimental_use_sh_toolchain_for_bootstrap_process_wrapper",
    build_setting_default = False,
)
